/*
 * Copyright (C) 2017-2018 Alibaba Group Holding Limited. All Rights Reserved.
 *
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TTS_CLOUD_ENGINE_H_
#define TTS_CLOUD_ENGINE_H_

#include <string>
#include "tts_listener.h"

/**
* @file cloud_tts.h
* @brief This file contains TTSEngine public interface defined by AliOS,
* and is shared by the platform independent voice framework and the vendor specific Implementation.
***/

namespace alios {
typedef enum {
    PCM = 0,
    WAV = 1,
    MP3 = 2,
} TTSFormatType;

class TTSCloudEngine {
public:
    TTSCloudEngine() {}
    virtual ~TTSCloudEngine() {}
    /**
    * @brief 初始化引擎
    * @param
    * @return
    */
    virtual int Initialize(const std::string &output_path) = 0;
    /**
    * @brief 断开连接，重置
    * @param
    * @return
    */
    virtual int Uninitialize() = 0;
    /**
    * @brief 设置tts合成的回调函数
    * @param TTSCloudEngineListener	回调的监听函数
    * @return
    */
    virtual void SetListener(TTSEngineListener* listener) = 0;
    /**
    * @brief 音频采样率sample_rate设置
    * @note 包含8000, 16000.可选参数, 默认是16000
    * @param value 音频采样率
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetSampleRate(int value) = 0;
    /**
    * @brief tts发音人设置
    * @note 范围是0~10, 可选参数, 默认0
    * @param value 发音人ID
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetVoiceId(int voiceId) = 0;
    /**
    * @brief tts发音人设置
    * @note 范围是0~10, 可选参数, 默认0
    * @param value 发音人ID
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetVoiceId(const std::string &voiceId) = 0;
    /**
    * @brief 音量volume设置
    * @note 范围是0~100, 可选参数, 默认50
    * @param value 音量
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetVolume(int value) = 0;
    /**
    * @brief 语速speech_rate设置
    * @note 范围是0~2, 可选参数, 默认是1, 对应着：快、中、慢
    * @param value 语速
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetSpeechRate(int value) = 0;
    /**
    * @brief 语调pitch_rate设置
    * @note 范围是-500~500, 可选参数, 默认是0
    * @param value 语调
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetPitchRate(int value) = 0;
    /**
    * @brief 设置Socket接收超时时间
    * @note
    * @param value 超时时间
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetTimeout(int value) = 0;
    /**
    * @brief 音频编码格式Format设置
    * @note 可选参数, 默认是pcm. 支持的格式pcm, wav, mp3
    * @param value 音频编码格式字符串
    * @return 成功则返回0，否则返回-1
    */
    virtual int SetFormat(TTSFormatType value) = 0;
    /**
    * @brief 启动tts合成
    * @note 非阻塞操作
    * @return 成功则返回0，否则返回-1
    */
    virtual int Start(const std::string &text) = 0;
    /**
    * @brief 会与服务端确认关闭，正常停止tts合成
    * @note 非阻塞操作
    * @return 成功则返回0，否则返回-1
    */
    virtual int Stop() = 0;
    /**
    * @brief set machine unique ID
    * @param[uuid] param uuid
    */
    virtual void SetUuid(const std::string &uuid) = 0;
    /**
    * @brief 通知服务端提前建立连接
    * @return
    */
    virtual void Connect() = 0;
    /**
    * @brief 获取引擎版本号
    * @return 引擎版本号
    */
    virtual const char *GetVersion() = 0;
};

}  // namespace alios

#if __GNUC__ >= 4
#  define CLOUD_TTS_EXPORT_API __attribute__ ((visibility ("default")))
#  define CLOUD_TTS_IMPORT_API __attribute__ ((visibility ("default")))
#  define CLOUD_TTS_INTERNAL   __attribute__ ((visibility ("hidden")))
#else
/** Visibility attribute to show method definitions */
#  define CLOUD_TTS_EXPORT_API
/** Visibility attribute to show declarations */
#  define CLOUD_TTS_IMPORT_API
/** Visibility attribute to hide declarations */
#  define CLOUD_TTS_INTERNAL
#endif

#define CLOUD_TTS_CREATEENGINE_SYM "CLOUD_TTS_CreateLocalEngine"
#define CLOUD_TTS_DESTROYENGINE_SYM "CLOUD_TTS_DestroyLocalEngine"

/*----------------------------------------------------------------------*/
/*                        Function Prototypes                           */
/*----------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

//
// TTS Engine library default entry points.
// TTS_CreateCloudEngine/TTS_DestroyCloudEngine.
//


typedef alios::TTSCloudEngine* (*TTS_CreateCloudEngineFunc)();
typedef void (*TTS_DestroyCloudEngineFunc)(alios::TTSCloudEngine* engine);

#ifdef __cplusplus
}  /* end extern "C" */
#endif
#endif // TTS_CLOUD_ENGINE_H_
